package edu.sctu.yueding.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2016/4/14.
 */
public class DateUtils {

    // 将字符串转为时间戳
    public static String getTime(String user_time) {

        String re_time = null;

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d;
        try {

            d = sdf.parse(user_time);
            long l = d.getTime();
            String str = String.valueOf(l);
            re_time = str.substring(0, 10);

        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return re_time;

    }

    // 将时间戳转为字符串
    public static String getStrTime(String cc_time) {

        String re_StrTime = null;



        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        long lcc_time = Long.valueOf(cc_time);
        re_StrTime = sdf.format(new Date(lcc_time));

//        re_StrTime =   sdf.format(lcc_time);

        return re_StrTime;

    }

//    public static String cha(long time){
//        long nowTime = Long.parseLong(getTime(getCurrentTime()));
//
//
//    }

    public static String getCurrentTime() {

        String str = null;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm ");
        Date curDate = new Date(System.currentTimeMillis());
        str = formatter.format(curDate);

        return str;
    }

    public static String getTime() {

        String str = null;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date curDate = new Date(System.currentTimeMillis());
        str = formatter.format(curDate);

        return str;
    }


}
